<template>
  <div>正在登录，请耐心等待</div>
</template>

<script>
import { mapActions } from 'vuex'
import { timeFix } from '@/utils/util'

export default {
  name: 'easyLogin',
  data() {
    return {

    }
  },
  created() {
    this.doOAuth2Login()
  },
  methods: {
    ...mapActions(['EasyWork']),

    /** 进行OAuth2登录操作 */
    doOAuth2Login() {
      // 判断是否携带了Token，是就说明登录成功
      if (this.$route.query.code) {
        this.code = this.$route.query.code
        this.doThirdLogin()
      }
    },

    // 根据token执行登录
    doThirdLogin() {
      let param = {
        code: this.code
      }
      this.EasyWork(param).then(res => {
        if (res.success) {
          this.loginSuccess()
        } else {
          this.requestFailed(res)
        }
      })
    },
    loginSuccess() {
      this.$router.push({ path: "/dashboard/analysis" })
      // this.$notification.success({
      //   message: '欢迎',
      //   description: `${timeFix()}，欢迎回来`,
      // });
    },
    requestFailed(err) {
      this.$notification['error']({
        message: '登录失败',
        description: ((err.response || {}).data || {}).message || err.message || "请求出现错误，请稍后再试",
        duration: 4,
      });
    },

  },
}
</script>

<style scoped></style>
